package com.fourpointsolutions.flex.utils
{
    public class LoremIpsumUtil
    {
        public static const ipsumText:String = "Lorem ipsum dolor sit amet " 
            + "consectetuer ipsum quis at lacinia auctor. Tincidunt auctor "
            + "Curabitur lacus elit massa eget quis vitae egestas semper. Mus "
            + "arcu nibh tempus laoreet nisl vitae tellus tempor turpis "
            + "tincidunt. Laoreet pellentesque Phasellus lacinia convallis ut "
            + "consectetuer velit enim velit et. Tellus Morbi lacus nec tellus "
            + "sapien tempus pretium laoreet purus In. Ante metus justo "
            + "tristique.";
            
        private static var ipsumArray:Array = ipsumText.split(" ");

        public function LoremIpsumUtil()
        {
        }
        
        public static function getSentence(wordCount:int):String {
            var returned:String = "";
            var ipsumArraySize:int = ipsumArray.length;
            var generatedWordCount:int = 0;
            var index:int;
            var nextWord:String;

            if (wordCount > 0) {
                while (generatedWordCount < wordCount) {
                    index = Math.floor(Math.random() * ipsumArraySize);
                    nextWord = String(ipsumArray[index]).toLowerCase().replace(".","");
                    returned += nextWord + " ";
                    generatedWordCount++;
                }
                
                returned = returned.charAt(0).toUpperCase()
                    + returned.substr(1).substr(0, returned.length - 2) + ".";
            }
            return returned;
        }

    }
}